package jihe_set_of_APIdemo;

import java.util.ArrayList;
import java.util.ListIterator;

/**
 * @author ChenYongHao
 * @date 2023/5/4 13:45
 * @desc
 */
public class List_TestDemo {
    public static void main(String[] args) {

        java.util.List<String> arrayList = new ArrayList<>();
        arrayList.add("aaa");
        arrayList.add("bbb");
        arrayList.add("ccc");
        arrayList.add("ddd");
        //使用迭代器删除
        ListIterator<String> listIteratorTest = arrayList.listIterator();
        while (listIteratorTest.hasNext()) {
            String next = listIteratorTest.next();
            if (next.equals("bbb")) {
                listIteratorTest.remove();
            }
        }
        //使用迭代器删除
        while (listIteratorTest.hasPrevious()) {
            String previous = listIteratorTest.previous();
            if (previous.equals("ccc")) {
                listIteratorTest.remove();
            }
        }
        arrayList.forEach(System.out::println);
    }
}
